//! Header for the class MusicPlayer
#ifndef MUSICPLAYER_H
#define MUSICPLAYER_H
//! Represents a music player which is able to add, remove,
//! play, search or get the duration of songs, albums and
//! music collections.
/*!
	The class MusicPlayer implements several functions which
	are adding, removing, playing, searching or getting the duration
	of MusicMedia. It uses internally a std::list of MusicMedia*
	which holds all MusicMedias.
	\class MusicPlayer
	\author Andreas Lehner
	\date 06.12.2012
*/
#include "Object.h"
#include <list>
#include "MusicMedia.h"

class MusicPlayer {
public:
	//! Function to add a MusicMedia to list of MusicMedia*.
	/*!
		The function pushes back a media of type MusicMedia* to the
		list, if the pointer is valid.
		\param media The music media which will be added.
		\throw std::exception Throws an exception on an invalid pointer.
	*/
	void AddMedia(MusicMedia* media);
	//! Function to remove a MusicMedia from list of MusicMedia*.
	/*!
		The function erases a media of type MusicMedia* of the
		list, if the pointer is valid and the media is found in the list.
		Note: Only the pointer will be removed from the list, allocated
		memory for the media will not be freed!
		\param media The music media which will be removed.
		\throw std::exception Throws an exception on an invalid pointer.
	*/
	void RemoveMedia(MusicMedia* media);
	//! Function to play all medias from list of MusicMedia*.
	/*!
		The function plays all medias found in the list of MusicMedia*
		by printing them to std::cout. All medias will be visited by the
		Player Visitor and printed out.
	*/
	void Play();
	//! Function to search for a MusicMedia from list of MusicMedia*.
	/*!
		The function searches for all medias which concur with the search
		string. If at least one media is found, it will be printed to std::cout.
		All medias will be visited by the Finder Visitor.
		\param search The name of the media to be searched for.
	*/
	void Search(std::string const& search);
	//! Function to get the duration of a MusicMedia or of all medias from list of MusicMedia*.
	/*!
		The function searches for all medias which concur with the search
		string. If at least one media is found, it will be printed to std::cout.
		All medias will be visited by the Finder Visitor.
		\param song The name of the media where the duration is required.
		If no value is passed, the duration of all medias will be added and returned.
		\return TDuration A struct which holds the minutes and secounds of a song 
		or all songs.
	*/
	TDuration GetDuration(std::string const& song = "") const;

private:
	//helper method for printing the names of found medias used in function Search()
	static void printfoundmedia(MusicMedia * media);
	//typedef for the list of MusicMedia*
	typedef std::list<MusicMedia*>::iterator TPlaylistIterator;
	typedef std::list<MusicMedia*>::const_iterator TPlaylistConstIterator;
	//the playlist holds all music medias which are currently in the music player
	std::list<MusicMedia*> mPlaylist;
};

#endif